
import 'package:yp/config/config.dart';

import '../entity/entity_factory.dart';

class HttpResponseEntity<T> {
  String resultCode;
  String message;
  T data;

  HttpResponseEntity({this.data, this.message, this.resultCode});

  HttpResponseEntity.fromJson(Map<String, dynamic> json) {
    /// 由于后端接口可能不规范 所以可能接口失败的时候data也有值 这里做好处理
    data = json['data'] != null
        ? EntityFactory.generateObject<T>(json['data'])
        : null;
    resultCode = json[Config.API_CODE_FIELD_NAME].toString();
    message = json[Config.API_MESSAGE_FIELD_NAME].toString();
  }

  @override
  String toString() {
    return 'HttpResponseEntity{resultCode: $resultCode, message: $message, data: $data}';
  }
}
